angular.module('date-format', [])
# 修正JS的Date类型format方法
.run () ->
    Date.prototype.format = (format) ->
        date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        }
        if (/(y+)/i.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))

        for v ,k of date
            if (new RegExp("("+v+")").test(format))
                format = format.replace(RegExp.$1, if RegExp.$1.length == 1 then [k] else ("00" + k).substr(("" + k).length))
        return format
